import os

import requests
from bs4 import BeautifulSoup

from utils import dict_util, parse_util, excel_util, read_config

url = 'https://jc.zhcw.com/port/client_json.php?callback=jQuery112204232138896188218_1641524508681&transactionType=10001001&lotteryId=1&' \
      'issueCount=50&startIssue=&endIssue=&startDate=&endDate=&type=0&pageNum=1&pageSize=30&tt=0.5996099474653397&_=1641524508684'


def ssq():
    u = 'https://datachart.500.com/ssq/history/history.shtml'
    resp = requests.get(u)
    soup = BeautifulSoup(resp.content, 'html.parser')
    items = soup.tbody.find_all('tr')
    arr = []
    for item in items:
        hong1 = int(item.find_all('td')[1].contents[0])
        hong2 = int(item.find_all('td')[2].contents[0])
        hong3 = int(item.find_all('td')[3].contents[0])
        hong4 = int(item.find_all('td')[4].contents[0])
        hong5 = int(item.find_all('td')[5].contents[0])
        hong6 = int(item.find_all('td')[6].contents[0])
        lan7 = int(item.find_all('td')[7].contents[0])
        arr.append([hong1, hong2, hong3, hong4, hong5, hong6, lan7])
    for a in arr:
        print(a)


def ssqhtml():
    arr = excel_util.get_excel_info(os.path.join(read_config.data_path, 'result', 'ssq', '双色球'), '')
    arr.reverse()
    arr_len = len(arr)
    hong_all13 = {}
    hong_all23 = {}
    hong_all32 = {}
    hong_all31 = {}
    hong_all = {}
    for i in range(1, 34):
        hong_all13[i] = 0
        hong_all32[i] = 0
        hong_all23[i] = 0
        hong_all31[i] = 0
        hong_all[i] = 0

    lan_all = {}
    for i in range(1, 17):
        lan_all[7] = 0
    for i in range(arr_len):
        for j in range(6):
            if i < int(arr_len / 3):
                dict_util.put_int_add(hong_all13, arr[i][j], 1)
            if i < int(arr_len / 3 * 2):
                dict_util.put_int_add(hong_all23, arr[i][j], 1)
            if i > int(arr_len / 3):
                dict_util.put_int_add(hong_all32, arr[i][j], 1)
            if i > int(arr_len / 3) * 2:
                dict_util.put_int_add(hong_all31, arr[i][j], 1)
            dict_util.put_int_add(hong_all, arr[i][j], 1)
        dict_util.put_int_add(lan_all, arr[i][6], 1)
    hong13 = parse_util.dict_kv_to_list_dict(hong_all13)
    hong23 = parse_util.dict_kv_to_list_dict(hong_all23)
    hong32 = parse_util.dict_kv_to_list_dict(hong_all32)
    hong31 = parse_util.dict_kv_to_list_dict(hong_all31)
    hong = parse_util.dict_kv_to_list_dict(hong_all)
    lan = parse_util.dict_kv_to_list_dict(lan_all)
    hong13 = sorted(hong13, key=lambda x: x['v'], reverse=True)
    hong23 = sorted(hong23, key=lambda x: x['v'], reverse=True)
    hong32 = sorted(hong32, key=lambda x: x['v'], reverse=True)
    hong31 = sorted(hong31, key=lambda x: x['v'], reverse=True)
    hong = sorted(hong, key=lambda x: x['v'], reverse=True)
    lan = sorted(lan, key=lambda x: x['v'], reverse=True)

    # 中奖规则
    # 一 1蓝6红
    # 二 6红
    # 三 1蓝5红
    # 四 5红 / 1蓝4红
    # 五 4红 / 1蓝3红
    # 六 1蓝 / 1蓝1红 / 1蓝2红

    print('end')


if __name__ == '__main__':
    ssqhtml()
